"""
MongoDB初始化脚本
"""
import os
import sys
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.append(str(project_root))

from src.data_collection.db_init import MongoDBInitializer
from src.data_collection.config import (
    MONGODB_HOST,
    MONGODB_PORT,
    MONGODB_USERNAME,
    MONGODB_PASSWORD,
    DB_NAME
)

def main():
    # 初始化MongoDB
    initializer = MongoDBInitializer(MONGODB_HOST, MONGODB_PORT)
    
    # 执行初始化
    success = initializer.initialize_database(
        db_name=DB_NAME,
        username=MONGODB_USERNAME,
        password=MONGODB_PASSWORD
    )
    
    if success:
        print("MongoDB初始化成功！")
        
        # 测试连接
        if initializer.check_connection(MONGODB_USERNAME, MONGODB_PASSWORD, DB_NAME):
            print("连接测试成功！")
        else:
            print("连接测试失败！")
    else:
        print("MongoDB初始化失败！")

if __name__ == "__main__":
    main() 